package com.stx.blog.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.stx.blog.dao.BlogDAO;
import com.stx.blog.service.BlogService;
import com.stx.blog.vo.BlogVO;
import com.stx.category.vo.CategoryVO;
import com.stx.user.vo.UserVO;

public class BlogAction extends ActionSupport implements SessionAware {
	private UserVO uservo;
	private BlogService blogservice;
	private BlogDAO blogdao;
	private BlogVO blogvo;
	private List<BlogVO> blogList = new ArrayList<BlogVO>();
	private CategoryVO categoryVO = null;
	private Map<String, Object> session;
	private int myorall;

	private String blogID;

	private List<CategoryVO> categoryList = new ArrayList<CategoryVO>();

	public String listCatgoryToAddBlog() {
		setCategoryList(blogservice.listCatgoryToAddBlog());

		return "listCatgoryToAddBlog";
	}

	public String listCatgoryForEditBlog() {
		blogvo.setBlogID(blogvo.getBlogID());

		setCategoryList(blogservice.listCatgoryToAddBlog());

		return "listCatgoryForEditBlog";
	}

	public String listBlog() {
		String userID = ((UserVO) (session.get("uservo"))).getUserid();
		blogList = blogservice.listBlog(userID);
		return "listBlog";
	}

	public String listAllBlog() {

		blogList = blogservice.listAllBlog();
		return "listAllBlog";
	}

	public String addBlog() {
		blogvo.setUserID(((UserVO) (session.get("uservo"))).getUserid());
		blogservice.addBlog(blogvo);
		return "listBlog";

	}

	public String deleteBlog() {
		blogservice.deleteBlog(blogID);

		return "listBlog";
	}

	public String editBlog() {

		blogservice.editBlog(blogvo);
		return "success";
	}

	public String getBlogByBid() {
		blogvo = blogservice.getBlogByBid(blogID);

		if (myorall == 1) {
			return "getUnEditableBlog";

		} else {
			return "getBlog";
		}
	}

	public String getBlogForEdit() {

		blogvo = blogservice.getBlogByBid(blogID);
		return "getBlog";
	}

	public BlogService getBlogservice() {
		return blogservice;
	}

	public void setBlogservice(BlogService blogservice) {
		this.blogservice = blogservice;
	}

	public BlogDAO getBlogdao() {
		return blogdao;
	}

	public void setBlogdao(BlogDAO blogdao) {
		this.blogdao = blogdao;
	}

	public BlogVO getBlogvo() {
		return blogvo;
	}

	public void setBlogvo(BlogVO blogvo) {
		this.blogvo = blogvo;
	}

	public List<BlogVO> getBlogList() {
		return blogList;
	}

	public void setBlogList(List<BlogVO> blogList) {
		this.blogList = blogList;
	}

	public UserVO getUservo() {
		return uservo;
	}

	public void setUservo(UserVO uservo) {
		this.uservo = uservo;
	}

	public List<CategoryVO> getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List<CategoryVO> categoryList) {
		this.categoryList = categoryList;
	}

	public String getBlogID() {
		return blogID;
	}

	public void setBlogID(String blogID) {
		this.blogID = blogID;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public int getMyorall() {
		return myorall;
	}

	public void setMyorall(int myorall) {
		this.myorall = myorall;
	}

}
